package com.xxxx.server.controller;


import com.xxxx.server.pojo.Department;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2022-04-13
 */
@RestController
@RequestMapping("/system/basic/department")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation("获取所有部门")
    @GetMapping("/")
    public List<Department> getalldep(){
        return departmentService.getalldep();
    }


    @ApiOperation("添加部门")
    @PostMapping("/")
    public RespBean adddep(@RequestBody Department department) {
        department.setEnabled(true);
        departmentService.adddep(department);
        if (department.getResult()==1){
            return RespBean.success("添加成功");
        }else {
            return RespBean.error("添加失败");
        }
    }


    @ApiOperation("删除部门")
    @DeleteMapping("/{did}")
    public RespBean deletedep(@PathVariable("did") Integer did){
       return departmentService.deletedep(did);
    }

}
